#ifndef CHANNEL_H
#define CHANNEL_H


#include <sys/queue.h>
#include "common.h"
#include "conf.h"



struct socket_connections_list
{
    struct socket_connection *socket_connection;
    LIST_ENTRY(socket_connections_list) next;
};

LIST_HEAD(socket_connections_list_header, socket_connections_list);


struct channels_list
{
    struct channel *channel;
    LIST_ENTRY(channels_list) next;
};

#define MAX_CHANNELS 60000
#define MAX_SOCKET_CONNECTIONS_PER_CHANNEL 4
LIST_HEAD(channels_list_head, channels_list);


struct channel
{
    uint64_t recv_bytes;
    uint64_t send_bytes;

    struct socket_connections_list_header socket_connections_list_header;
} align_type_size(CPU_CACHE_LINE_SIZE);

extern int init_channels ();
extern int destory_channels ();

extern int create_channel (int *channel_id);
extern int delete_channel (int channel_id);



#define MAX_SOCKET_CONNECTIONS 50000

LIST_HEAD(socket_connection_list_header, socket_connection_list);


struct socket_connection
{
    uint32_t read_bytes;
    uint32_t write_bytes;
    struct channel_header channel_header;
} align_type_size(CPU_CACHE_LINE_SIZE);

extern int init_socket_connections ();
extern int destory_socket_connections ();

extern int add_socket_connection ();
extern int remove_socket_connection ();

extern int join_channel ();
extern int leave_channel ();






#endif
